package com.hrg.rds.infra.connect.protocol.modbus;

import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

@Getter
public enum ModbusMemoryArea {
	Coils("线圈", 1, 1, "RW", "0x", "coil"),
	DiscreteInputs("离散输入", 1, 1, "R", "1x", "discrete-input:"),
	InputRegisters("输入寄存器", 1, 16, "R", "3x", "input-register:"),
	HoldingRegisters("保持寄存器", 1, 16, "RW", "4x", "holding-register:"),
	ExtendedRegister("扩展寄存器", 0, 16, "RW", "6x", "input-register:");

	ModbusMemoryArea(String description, int initIdx, int bitLength, String access, String prefixHex, String prefixEn) {
		this.description = description;
		this.initIdx = initIdx;
		this.bitLength = bitLength;
		this.access = access;
		this.prefixHex = prefixHex;
		this.prefixEn = prefixEn;
	}

	private final String description;
	private final int initIdx;
	private final int bitLength;
	private final String access;
	private final String prefixHex;
	private final String prefixEn;

	private static final Map<String, ModbusMemoryArea> map = new HashMap<>();

	static {
		for (ModbusMemoryArea modbusMemoryArea : ModbusMemoryArea.values()) {
			map.put(modbusMemoryArea.name(), modbusMemoryArea);
		}
	}
	public static ModbusMemoryArea get(String name) {
		return map.get(name);
	}
}
